package chapter04;

public class AVLTree<E extends Comparable<? super E>> {

    private class Node {
        public E e;

        public Node left;

        public Node right;

        public int height;

        public Node(E e) {
            this(e, null, null, 0);
        }

        private Node(E e, Node left, Node right, int height) {
            this.e = e;
            this.left = left;
            this.right = right;
            this.height = height;
        }
    }

    private Node root;

    private int size;

    public AVLTree() {
        this(null, 0);
    }

    private AVLTree(Node root, int size) {
        this.root = root;
        this.size = size;
    }

    private int getHeight(Node node) {
        if (node == null) {
            return 0;
        }
        return node.height;
    }

    public int getSize() {
        return size;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    private int getBalanceFactor(Node node) {
        if (node == null) {
            return 0;
        }
        return getHeight(node.left) - getHeight(node.right);
    }

    public boolean isBalanced() {
        return isBalanced(root);
    }

    private boolean isBalanced(Node node) {
        if (node == null) {
            return true;
        }
        int balanceFactory = Math.abs(getBalanceFactor(node));
        if (balanceFactory > 1) {
            return false;
        }else {
            return isBalanced(node.left) && isBalanced(node.right);
        }
    }


    private Node rightRotate(Node y) {
        Node x = y.left;
        Node t3 = x.right;
        return null;
    }




}
